#include "lan2caldelegate.h"

#include <QPainter>
#include <QDebug>
#include <QModelIndex>
LAN2STA
Lan2CalDelegate::Lan2CalDelegate(QObject *parent): QStyledItemDelegate(parent)
{
    //  te=new QTextEdit();
    //  connect(te,SIGNAL(textChanged()),this,SLOT(slot_says()));

}



void Lan2CalDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    int xpos=option.rect.x();
    int ypos=option.rect.y();
    int mw=option.rect.width();
    int mh=option.rect.height();

    if( option.state & QStyle::State_MouseOver){


        painter->save();
        painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
        painter->setPen(QPen(QColor("#aaff00e2"),1));
//        painter->setBrush(QBrush(QColor("#aaff00e2"),Qt::SolidPattern));
        painter->drawEllipse(QPointF(xpos+mw/2.0,ypos+mh/2.0),20,20);
        painter->setPen(QPen(QColor("#000000"),1));
        painter->drawText(QRect(xpos,ypos,mw,mh),Qt::AlignCenter,index.data().toString());
        painter->restore();
//        qDebug()<<"state"<<index.data()<<option.rect;
        //        QString str=index.data().toString();
        //        int xpos=option.rect.x();
        //        int ypos=option.rect.y();
        //        int mw=option.rect.width();
        //        int mh=option.rect.height();
        //        te->clear();
        //        te->append(QString("%1 %2 %3 %4 %5").arg(str).arg(xpos).arg(ypos).arg(mw).arg(mh));

        //        emit sign_data(str,xpos,ypos,mw,mh);
    }
    else if((option.state & QStyle::State_Selected)){


        painter->save();
        painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
        painter->setPen(QPen(QColor("#ff00e2"),1));
        painter->setBrush(QBrush(QColor("#ff00e2"),Qt::SolidPattern));
        painter->drawEllipse(QPointF(xpos+mw/2.0,ypos+mh/2.0),20,20);
        painter->setPen(QPen(QColor("#000000"),1));
        painter->drawText(QRect(xpos,ypos,mw,mh),Qt::AlignCenter,index.data().toString());

        painter->restore();

    }else if(option.state & QStyle::State_HasFocus){

        painter->save();
        painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
        painter->setPen(QPen(QColor("#ff00e2"),1));
        painter->setBrush(QBrush(QColor("#ff00e2"),Qt::SolidPattern));
        painter->drawEllipse(QPointF(xpos+mw/2.0,ypos+mh/2.0),20,20);
        painter->setPen(QPen(QColor("#000000"),1));
        painter->drawText(QRect(xpos,ypos,mw,mh),Qt::AlignCenter,index.data().toString());

        painter->restore();

    }else{

        QStyledItemDelegate::paint(painter,option,index);
    }

}

LAN2END
